﻿package com.firewolf.iteratorAndComponent.iterator.self.menus;

import com.firewolf.iteratorAndComponent.iterator.common.MyMenuItem;
import com.firewolf.iteratorAndComponent.iterator.self.iterators.DinerMenuIterator;
import com.firewolf.iteratorAndComponent.iterator.self.iterators.MyIterator;

/**
 * 晚餐菜单,是用数组实现的
 * @author Administrator
 *
 */
public class DinerMenu implements IMenu{
	private final int MAX_ITEMS = 6;
	private int numberOfItems = 0;
	private MyMenuItem[] menuItems;
	public DinerMenu() {
		menuItems = new MyMenuItem[MAX_ITEMS];
		
		//添加一些菜单项，正常情况应该在调用菜单的类里面调用，这里为了方便，就在这里先添加了
		addItem("potato", "this is potato", true, 8.0);
		addItem("chiken egg", "this is chiken egg", true, 12.0);
		addItem("duck", "this is duck", false, 16.0);
		addItem("pig", "this is pig", false, 8.0);
	}
	/**
	 * 增加一个菜单项
	 * @param name
	 * @param description
	 * @param vegetarian
	 * @param price
	 */
	public void addItem(String name, String description, boolean vegetarian,
			double price){
		MyMenuItem menuItem = new MyMenuItem(name, description, vegetarian, price);
		if(numberOfItems >= MAX_ITEMS){
			System.out.println("Sorry , menu is full , Can't add item to menu");
		}else{
			menuItems[numberOfItems++] = menuItem;
		}
	}
	@Override
	public MyIterator getIterator() {
		return new DinerMenuIterator(menuItems);
	}
}
